import { defineStore } from 'pinia'
import { Add, getGroups, Lists, getStatus, getRecordList, getMember } from '@/api/Message';

export const useMessageStore = defineStore('message', {
  // state:{
  //   list:[
  //     {
  //       id: 1,
  //       sendStart:'2024-01 14:30',
  //       title: "2023-2024学年第二学期期末考试监考安排通知",
  //       group:['全体专任教师'],
  //       source:'教务处',
  //       status: {
  //         count: 120,
  //         readed:100,
  //         done: 20
  //       }
  //     },
  //     {
  //       id: 2,
  //       sendStart:'2024-01 14:30',
  //       title: "2023-2024学年第二学期期末考试监考安排通知",
  //       group:['全体专任教师'],
  //       source:'教务处',
  //       status: {
  //         count: 150,
  //         readed:120,
  //         done: 20
  //       }
  //     },
  //     {
  //       id: 3,
  //       sendStart:'2024-01 14:30',
  //       title: "2023-2024学年第二学期期末考试监考安排通知",
  //       group:['全体专任教师'],
  //       source:'教务处',
  //       status: {
  //         count: 180,
  //         readed:120,
  //         done: 20
  //       }
  //     }
  //   ]
  // },
  state: () => ({
    list:[
      {
        id: 1,
        sendStart:'2024-01 14:30',
        title: "2023-2024学年第二学期期末考试监考安排通知1",
        group:['全体专任教师'],
        source:'教务处',
        status: {
          count: 120,
          readed:100,
          done: 20
        }
      },
      {
        id: 2,
        sendStart:'2024-01 14:30',
        title: "2023-2024学年第一学期期末考试监考安排通知2",
        group:['全体专任教师'],
        source:'教务处',
        status: {
          count: 150,
          readed:120,
          done: 20
        }
      },
      {
        id: 3,
        sendStart:'2024-01 14:30',
        title: "2024-2025学年第一学期期末考试监考安排通知3",
        group:['全体专任教师'],
        source:'教务处',
        status: {
          count: 180,
          readed:120,
          done: 20
        }
      },
      {
        id: 4,
        sendStart:'2024-01 14:30',
        title: "2023-2024学年第二学期期末考试监考安排通知1",
        group:['全体专任教师'],
        source:'教务处',
        status: {
          count: 120,
          readed:100,
          done: 20
        }
      },
      {
        id: 5,
        sendStart:'2024-01 14:30',
        title: "2023-2024学年第二学期期末考试监考安排通知1",
        group:['全体专任教师'],
        source:'教务处',
        status: {
          count: 120,
          readed:100,
          done: 20
        }
      },
      {
        id: 6,
        sendStart:'2024-01 14:30',
        title: "2023-2024学年第二学期期末考试监考安排通知1",
        group:['全体专任教师'],
        source:'教务处',
        status: {
          count: 120,
          readed:100,
          done: 20
        }
      },
      {
        id: 7,
        sendStart:'2024-01 14:30',
        title: "2023-2024学年第二学期期末考试监考安排通知1",
        group:['全体专任教师'],
        source:'教务处',
        status: {
          count: 120,
          readed:100,
          done: 20
        }
      },
      {
        id: 8,
        sendStart:'2024-01 14:30',
        title: "2023-2024学年第二学期期末考试监考安排通知1",
        group:['全体专任教师'],
        source:'教务处',
        status: {
          count: 120,
          readed:100,
          done: 20
        }
      },
      {
        id: 9,
        sendStart:'2024-01 14:30',
        title: "2023-2024学年第二学期期末考试监考安排通知1",
        group:['全体专任教师'],
        source:'教务处',
        status: {
          count: 120,
          readed:100,
          done: 20
        }
      },
      {
        id: 10,
        sendStart:'2024-01 14:30',
        title: "2023-2024学年第二学期期末考试监考安排通知1",
        group:['全体专任教师'],
        source:'教务处',
        status: {
          count: 120,
          readed:100,
          done: 20
        }
      },
      {
        id: 11,
        sendStart:'2024-01 14:30',
        title: "2023-2024学年第二学期期末考试监考安排通知1",
        group:['全体专任教师'],
        source:'教务处',
        status: {
          count: 120,
          readed:100,
          done: 20
        }
      },
      {
        id: 12,
        sendStart:'2024-01 14:30',
        title: "2023-2024学年第二学期期末考试监考安排通知1",
        group:['全体专任教师'],
        source:'教务处',
        status: {
          count: 120,
          readed:100,
          done: 20
        }
      },
      {
        id: 13,
        sendStart:'2024-01 14:30',
        title: "2023-2024学年第二学期期末考试监考安排通知1",
        group:['全体专任教师'],
        source:'教务处',
        status: {
          count: 120,
          readed:100,
          done: 20
        }
      },
      {
        id: 14,
        sendStart:'2024-01 14:30',
        title: "2023-2024学年第二学期期末考试监考安排通知1",
        group:['全体专任教师'],
        source:'教务处',
        status: {
          count: 120,
          readed:100,
          done: 20
        }
      },
      {
        id: 15,
        sendStart:'2024-01 14:30',
        title: "2023-2024学年第二学期期末考试监考安排通知1",
        group:['全体专任教师'],
        source:'教务处',
        status: {
          count: 120,
          readed:100,
          done: 20
        }
      },
      {
        id:16,
        sendStart:'2024-01 14:30',
        title: "2023-2024学年第二学期期末考试监考安排通知1",
        group:['全体专任教师'],
        source:'教务处',
        status: {
          count: 120,
          readed:100,
          done: 20
        }
      },
      {
        id: 17,
        sendStart:'2024-01 14:30',
        title: "2023-2024学年第二学期期末考试监考安排通知1",
        group:['全体专任教师'],
        source:'教务处',
        status: {
          count: 120,
          readed:100,
          done: 20
        }
      },
      {
        id: 18,
        sendStart:'2024-01 14:30',
        title: "2023-2024学年第二学期期末考试监考安排通知1",
        group:['全体专任教师'],
        source:'教务处',
        status: {
          count: 120,
          readed:100,
          done: 20
        }
      },
      {
        id: 19,
        sendStart:'2024-01 14:30',
        title: "2023-2024学年第二学期期末考试监考安排通知1",
        group:['全体专任教师'],
        source:'教务处',
        status: {
          count: 120,
          readed:100,
          done: 20
        }
      },
    ],
    group:[],
    groupList:[],
    status:null
  }),
  getters: {
    ListItem(){
      return this.list;
    },
    GroupList(){
      return this.group;
    },
    Group(){
      return this.groupList;
    }
  },
  actions: {
    async get(){
      return await Lists(10000001)
      .then(res=>{
        this.list.splice(0,this.list.length,...res.data.data)
        // console.log("res data==>");
        // console.log(res.data.data);
        // console.log(this.ListItem);
        
        return res;
      }).catch(err=>{
        console.log("res err==>");
        console.log(err);
        return null;
      })
    },
    removeItem(items) {
      const validIds = new Set(items); // 转换为 Set
      this.list = this.list.filter(item => !validIds.has(item.id));
      console.log(this.list);

    },
    async addItem(data) { 
      return await Add(data)
      .then(res=>{
        // console.log(res);
        
        return res.data;
        // console.log(res.data);
      }).catch(err=>{
        console.log(err);
      })
    },
    async HandleGroups(data) {
      return await getGroups(data).then(res =>{
        // console.log("------------");
        // console.log(res.data.data);
        this.groupList.splice(0,this.groupList.length,...res.data.data)
        const result = res.data.data.map(item=>{
          return {
            value: item[0],
            label: item[1]
          }
        })
        this.group.splice(0,this.group.length,...result)
        return res;
      }).catch(err=>{
        console.log(err);
        return err;
      })
    },
    async HandleStatus(data) {
      return await getStatus(data).then(res=>{
        return res.data
      })
    },
    async HandleRecord(data) {
      return await getRecordList(data).then(res=>{
        return res.data
      })
    },
    async HandleMember(data) {
      return await getMember(data).then(res=>res.data)
    }
  },
})